<?php
/**
 * getSign($data) 中 阿里支付 业务字段为 order_sn 系统订单   money 金额   body  商品描述  subject  商品名称
 * 
 *                   
 *                       
 *                    
 */
namespace  App\Wolf\Pay;

use App\Baqi\Alipayapp\AlipayApp;

class PaySDK 
{

    public $payObj = '';//支付对象

    public $type;  //支付类型

    //选择不同的支付类
    public function __construct($type = 'alipayapp') 
    {
        $this->type = $type;
    }

    /**
     * app 支付获得签名数据
     * 目前仅 支持微信和支付宝 
     * @param  [type] $data [业务参数]
     * @return [type]       [description]
     */
    public function getSign ($data)
    {
        return $this->payObj->getSign($data);
    }


    /**
     * app 支付 回调验证
     * 目前仅 支持微信和支付宝 
     * @param  [type] $data [支付平台回调参数]
     * @return [type]       [description]
     */
    public function notifyAppCheck ($data)
    {
        return $this->payObj->notifyCheck($data);
    }


    /**
     * pc 支付 
     * 目前只支持支付宝 即时到帐
     * @param  [type] $data [业务参数]
     * @return [type]       [description]
     */
    public function pcPay ($data)
    {
        return $this->payObj->pay($data);
    }

    /**
     * pc 支付 回调验证
     * 目前只支持支付宝 即时到帐
     * @param  [type] $data [支付平台回调参数]
     * @return [type]       [description]
     */
    public function notifyPcCheck ($data)
    {
        return $this->payObj->notifyCheck($data);
    }



    //设置支付配置参数
    public function setConfig($config) 
    {
        if ($this->type == 'alipayapp') {
            
            $this->payObj = new AlipayApp($config);
        }

        if ($this->type == 'alipaypc') {
            
            $this->payObj = new AlipayPc($config);
        }

        if ($this->type == 'wxpayapp') {
            
            $this->payObj = new WxpayApp($config);
        }

    }

    /**
     * 回调排错debug日志
     * @return [type] [description]
     */
    public function deBugLog($word = '') 
    {

        $fp = fopen($this->debugPath,"a");
        flock($fp, LOCK_EX) ;
        fwrite($fp,"执行日期：".strftime("%Y%m%d%H%M%S",time())."\n".$word."\n");
        flock($fp, LOCK_UN);
        fclose($fp);
    }

    /**
     * 获得bug数据
     * @return [type] [description]
     */
    public function getBugLog() 
    {
        $myfile =  fopen($this->debugPath, "r");
        $word = fread($myfile,filesize($path));
        return $word;
    }

}

?>